#include <cstdio>
#include "ImageLoader.h"

int load_rgb24_raw_data(ImageContext* image, const char* fileName, int width, int height)
{
    FILE* fs = fopen(fileName, "rb");
    if (!fs)
        return -1;
    int bufferSize = width*height * 3;
    uint8_t* pBuffer = (uint8_t*)malloc(bufferSize);
    if (!pBuffer)
    {
        fclose(fs);
        return -1;
    }
    int ret = fread(pBuffer, 1, bufferSize, fs);
    fclose(fs);
    if (ret != bufferSize)
    {
        return -1;
    }
    image->data.reset(pBuffer, ::free);
    image->width = width;
    image->height = height;
    return 0;
}